package com.audition.thread;

/**
 * @author ADMIN
 * @date 2021/3/7 20:37
 */
public class StopThread implements Runnable{
    /**
     * 正确终止线程
     */
    @Override
    public void run() {
        int count = 0;
        while (!Thread.currentThread().isInterrupted() && count < 1000) {
            System.out.println("count=" + count++);
        }

    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new StopThread());
        thread.start();
        Thread.sleep(5);
        thread.interrupt();

    }
}
